import xml.sax
from ast import parse
from cgitb import handler
from dataclasses import dataclass
from mimetypes import init
import xml.sax.handler


class BookHandler(xml.sax.handler.ContentHandler):
    def __init__(self) -> None:
        self.inTitle = False

    def startElement(self, name, attrs):
        if name == 'title':
            self.inTitle = True

    def characters(self, content):
        if self.inTitle:
            print(content)

    def endElement(self, name):
        if name == 'title':
            self.inTitle = False


parser = xml.sax.make_parser()
handler = BookHandler()
parser.setContentHandler(handler)
parser.parse('mybooks.xml')
